package com.atmilan.quartz.utils.product;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.atmilan.quartz.model.dto.efasion.EfasionProductResDTO;
import com.atmilan.quartz.utils.RestTemplateUtil;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * 拉取商品源数据
 */

@Slf4j
@Service
public class EfasionProductUtil {

    @Autowired
    RestTemplateUtil restTemplateUtil;

    @Value("${efasion.url.domain}")
    private String domain;
    @Value("${efasion.url.productPage}")
    private String productPage;
    @Value("${efasion.merchantNo}")
    private String merchantNo;

    /**
     * 商品分页查询
     * @author daigb
     * @date:  2022-06-14 17:10
     */
    public EfasionProductResDTO selectProductPage(Integer pageNow, Integer pageSize) throws Exception {
        EfasionProductResDTO efasionProductResDTO = null;
        try {
        	HashMap<String, String> parMap = new HashMap<String, String>();
            parMap.put("merchantNo", merchantNo);
            JSONObject result = restTemplateUtil.getData(domain + productPage + "?pageNow=" + pageNow + "&pageSize=" + pageSize, parMap);

            ObjectMapper mapper = new ObjectMapper();
            efasionProductResDTO = mapper.readValue(result.toJSONString(), EfasionProductResDTO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return efasionProductResDTO;
    }

}
